package com.jy.rhin.infra.repo.notfication.publish.po;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.jy.rhin.domain.notification.publish.entity.EnumPublishMessageNotifyStatus;
import com.jy.rhin.domain.notification.publish.entity.PublishMessageDO;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

/**
 * @author WeiQ
 * @date 2022/6/29 17:08
 */
@Data
@TableName("t_notification_log")
@NoArgsConstructor
public class PublishMessagePO {

    public PublishMessagePO(PublishMessageDO publishMessage) {
        this.id = publishMessage.getId();
        this.messageId = publishMessage.getMessageId();
        this.publisherCode = publishMessage.getPublisherCode();
        this.subscriberCode = publishMessage.getSubscriberCode();
        this.topicId = publishMessage.getTopicId();
        this.subscribeId = publishMessage.getSubscribeId();
        this.notifyStatus = publishMessage.getNotifyStatus().name();
        this.publishCount = publishMessage.getPublishCount();
        this.notifyTime = publishMessage.getNotifyTime();
        this.createTime = publishMessage.getCreateTime();
    }

    public PublishMessageDO toDO() {
        PublishMessageDO publishMessage = new PublishMessageDO();
        publishMessage.setId(this.id);
        publishMessage.setMessageId(this.messageId);
        publishMessage.setPublisherCode(this.publisherCode);
        publishMessage.setSubscriberCode(this.subscriberCode);
        publishMessage.setTopicId(this.topicId);
        publishMessage.setSubscribeId(this.subscribeId);
        publishMessage.setNotifyStatus(EnumPublishMessageNotifyStatus.valueOf(this.notifyStatus));
        publishMessage.setPublishCount(this.publishCount);
        publishMessage.setNotifyTime(this.notifyTime);
        publishMessage.setCreateTime(this.createTime);
        return publishMessage;
    }

    @TableId
    private Long id;
    /**
     * 通知消息记录表主键id
     */
    @TableField("message_id")
    private Long messageId;
    /**
     * 发布者
     */
    @TableField("publisher_code")
    private String publisherCode;
    /**
     * 订阅者
     */
    @TableField("subscriber_code")
    private String subscriberCode;
    /**
     * 主题id
     */
    @TableField("topic_id")
    private Long topicId;
    /**
     * 订阅id
     */
    @TableField("subscribe_id")
    private Long subscribeId;
    /**
     * 通知状态;INIT:初始化,DONE:已完成
     */
    @TableField("notify_status")
    private String notifyStatus;
    /**
     * 补偿次数
     */
    @TableField("publish_count")
    private Integer publishCount;
    /**
     * 通知时间;最后一次发送通知的时间,不论成功或失败
     */
    @TableField("notify_time")
    private Date notifyTime;
    /**
     * 创建时间
     */
    @TableField("create_time")
    private Date createTime;
}
